package receiveraddress

import (
	"context"
	"hotgo/internal/library/contexts"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"

	"hotgo/api/api/receiveraddress/v1"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {

	// 设置用户ID
	req.AdminMemberId = contexts.GetUserId(ctx)

	// 获取列表
	list, totalCount, err := service.SysReceiverAddress().List(ctx, &req.ReceiverAddressListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.ReceiverAddressListModel{}
	}

	res = new(v1.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
	err = service.SysReceiverAddress().Edit(ctx, &req.ReceiverAddressEditInp, true)
	return
}

func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) {
	err = service.SysReceiverAddress().Delete(ctx, &req.ReceiverAddressDeleteInp, true)
	return
}
